﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Xuanren_FrontEnd.Model;

namespace Xuanren_FrontEnd.Areas.Back.Controllers
{
    public class AdminController : Controller
    {
        private XuanrenTherapyEntities db = new XuanrenTherapyEntities();

        // GET: Admin
        public ActionResult Index()
        {
            {
                object uid = Session["uid"];
                //获取该用户的信息
                var un = Convert.ToInt32(uid);
                var obj = db.Admin.FirstOrDefault(x => x.id == un);
                return View(obj);

            }

        }

        //修改密码
        public ActionResult DealPwd(int Id, string OldPassword, string NewPassword)
        {
             
            {
                Admin admin = db.Admin.SingleOrDefault(p => p.id == Id);
                if (admin.password == OldPassword)
                {
                    //修改密码
                    admin.password = NewPassword;
                    int r = db.SaveChanges();
                    if (r > 0)
                    {
                        return Json(new { code = 0, msg = "修改密码成功" });
                    }
                    else
                    {
                        return Json(new { code = 1, msg = "修改密码失败" });
                    }
                }
                else
                {
                    return Json(new { code = 1, msg = "原密码错误" });
                }
            }
        }
        //退出
        public ActionResult SignOut()
        {
            Session.Remove("uid");
            Session.Remove("username");
            return Redirect("/Back/Home/Login");
        }
    }
}
